<?php
class HeaderController extends SilkControllerBase {
	
	function index($params) {
//		echo "<pre>"; var_dump($params); echo "</pre>";
		if( isset( $params["msg"] )) {
			$this->set("msg", $params["msg"]);
		}
		$get_params = "?";
		foreach($_GET as $key=>$value) $get_params .= "$key=$value&";
		$params["redirect"] = SilkRequest::get_calculated_url_base(true) . SilkRequest::get_requested_page() . $get_params;

		$this->set("div", "header");
		$links = array();
		$links["Home"] = SilkResponse::create_url(array(	"controller" => "homepage",
															"action" => "index"
															));
		$links["Browse"] = SilkResponse::create_url(array(	"controller" => "browse",
															"action" => "index"
															));
		if(SilkUserSession::get_current_user()) {
			$this->set("message", "Logged in as: ". $_SESSION["silk_user"]->params["username"]);
			
			$links["Dashboard"] = SilkResponse::create_url(array(	"controller" => "dashboard" ));
			$links["Logout"] = SilkResponse::create_url(array(	"controller" => "usermanager",
															"action" => "logout"
															));
		} else {
			$links["Register"] = SilkResponse::create_url(array(	"controller" => "mp",
															"action" => "register"
//		  													"redirect" => substr($params["redirect"], 0, strpos($params["redirect"], "?"))
															));
			$links["Login"] = SilkResponse::create_url(array("controller" => "usermanager",
	  													"action" => "login"
//	  													"redirect" => substr($params["redirect"], 0, strpos($params["redirect"], "?"))
	  													));
		}
		
		$links["Utils"] = SilkResponse::create_url(array(	"controller" => "silk_utils" ));
		$this->set("mainMenu", MenuManagerController::auto_menu(array("menuItems" => $links)));
		$this->set("currentLanguage", SilkLang::get_lang());
		$this->set("languageLinks", SilkLang::get_language_links());
	}
}

?>